package com.taobao.txc.client.aop;

import com.taobao.txc.common.LoggerInit;
import com.taobao.txc.common.LoggerWrap;
import com.taobao.txc.common.b.b;
import com.taobao.txc.common.b.c;
import com.taobao.txc.resourcemanager.mt.MtResourceManager;
import java.util.HashMap;
import org.apache.commons.lang.ClassUtils;
import org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

public class MTRelationShipManager
  extends BeanNameAutoProxyCreator
  implements ApplicationListener
{
  private static final LoggerWrap a = LoggerInit.logger;
  private HashMap<String, Object> b = new HashMap();
  private MtResourceManager c = null;
  private String[] d = new String[0];
  private Object e;
  
  public void setBeanNames(String[] paramArrayOfString)
  {
    this.d = paramArrayOfString;
    super.setBeanNames(paramArrayOfString);
  }
  
  protected synchronized Object wrapIfNecessary(Object paramObject1, String paramString, Object paramObject2)
  {
    if ((paramObject1 instanceof MtResourceManager))
    {
      this.c = ((MtResourceManager)paramObject1);
      return paramObject1;
    }
    this.e = paramObject1;
    return super.wrapIfNecessary(paramObject1, paramString, paramObject2);
  }
  
  protected boolean isMatch(String paramString1, String paramString2)
  {
    boolean bool = false;
    try
    {
      Class localClass = ClassUtils.getClass(paramString2);
      if (localClass.isInstance(this.e))
      {
        this.b.put(paramString2, this.e);
        bool = true;
      }
      else
      {
        bool = false;
      }
    }
    catch (ClassNotFoundException localClassNotFoundException)
    {
      bool = false;
    }
    if (a.c()) {
      a.debug("test beanName:" + paramString1 + " mappedName:" + paramString2 + " result:" + bool);
    }
    return bool;
  }
  
  public void onApplicationEvent(ApplicationEvent paramApplicationEvent)
  {
    if ((paramApplicationEvent != null) && ((paramApplicationEvent instanceof ContextRefreshedEvent)))
    {
      if (((ContextRefreshedEvent)paramApplicationEvent).getApplicationContext().getParent() != null) {
        a.info(paramApplicationEvent + " MTRelationShipManager init, not root context");
      } else {
        a.info(paramApplicationEvent + " MTRelationShipManager init, root context");
      }
      a.info(paramApplicationEvent + " MTRelationShipManager init finished!");
      if (this.c == null) {
        this.c = MtResourceManager.getTxcResourceManager();
      }
      if ((this.c != null) && (this.b.size() == this.d.length))
      {
        this.c.a(this.b);
        try
        {
          this.c.c();
        }
        catch (Throwable localThrowable)
        {
          throw c.a(new c(localThrowable, "unexpected error", b.m));
        }
      }
      else
      {
        if (this.c == null) {
          throw c.a(new c("MtResourceManager not be found!", b.f));
        }
        for (String str : this.d) {
          if (!this.b.containsKey(str)) {
            throw c.a(new c(String.format("The instance of %s not be found!", new Object[] { str }), b.g));
          }
        }
      }
    }
  }
}


/* Location:           C:\Users\ibm\Downloads\txc-yun-sample (1)\txc-yun-sample\lib\txc-client-2.0.72.jar
 * Qualified Name:     com.taobao.txc.client.aop.MTRelationShipManager
 * JD-Core Version:    0.7.0.1
 */